<script type="text/javascript" src="<?=PATH_URL.'static/js/admin/jquery.slugit.js'?>"></script>
<script type="text/javascript">
$(document).ready( function() {
	$("#titleAdmincp").slugIt({
		events: 'keyup blur',
		output: '#slugAdmincp',
		space: '-'
	});
});

function save(){
	var options = {
		beforeSubmit:  showRequest,  // pre-submit callback
		success:       showResponse  // post-submit callback
    };
	$('#frmManagement').ajaxSubmit(options);
}

function showRequest(formData, jqForm, options) {
	var form = jqForm[0];
	if(form.titleViAdmincp.value == '' || form.titleEnAdmincp.value == '' || form.titleGrAdmincp.value == ''){
		$('#txt_error').html('Please enter information!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}
}

function showResponse(responseText, statusText, xhr, $form) {
	if(responseText=='success'){
		location.href=root+"admincp/"+module+"/#/save";
	}

	if(responseText=='error-title-vi-exists'){
		$('#txt_error').html('Name Vietnam already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		$('#titleViAdmincp').focus();
		return false;
	}
	if(responseText=='error-title-en-exists'){
		$('#txt_error').html('Name English already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		$('#titleEnAdmincp').focus();
		return false;
	}
	if(responseText=='error-title-gr-exists'){
		$('#txt_error').html('Name Germany already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		$('#titleGrAdmincp').focus();
		return false;
	}

	if(responseText=='error-slug-exists'){
		$('#txt_error').html('Slug already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		$('#slugAdmincp').focus();
		return false;
	}

	if(responseText=='permission-denied'){
		show_perm_denied();
	}
}
</script>
<div class="gr_perm_error" style="display:none;">
	<p><strong>FAILURE: </strong><span id="txt_error">Permission Denied.</span></p>
</div>
<div class="table">
	<div class="head_table"><div class="head_title_edit"><?=$module?></div></div>
	<div class="clearAll"></div>

	<form id="frmManagement" action="<?=PATH_URL.'admincp/'.$module.'/save/'?>" method="post" enctype="multipart/form-data">
	<input type="hidden" value="<?=$id?>" name="hiddenIdAdmincp" />
	<div class="row_text_field_first">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Status:</td>
				<td class="right_text_field"><input <?php if(isset($result->status)){ if($result->status==1){ ?>checked="checked"<?php }}else{ ?>checked="checked"<?php } ?> type="checkbox" class="custom_chk" name="statusAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Name Vi:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->name_vi)) { print $result->name_vi; }else{ print '';} ?>" type="text" name="titleViAdmincp" id="titleViAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Name En:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->name_en)) { print $result->name_en; }else{ print '';} ?>" type="text" name="titleEnAdmincp" id="titleEnAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Name Gr:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->name_gr)) { print $result->name_gr; }else{ print '';} ?>" type="text" name="titleGrAdmincp" id="titleGrAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Download:</td>
				<td class="right_text_field"><input value="download" <?php if(isset($result->download) && $result->download > 0) { print 'checked' ;}?> type="checkbox" name="permAdmincp[]" id="downloadAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Upload:</td>
				<td class="right_text_field"><input value="upload" <?php if(isset($result->upload) && $result->upload > 0) { print 'checked' ;}?> type="checkbox" name="permAdmincp[]" id="uploadAdmincp" /></td>
			</tr>
		</table>
	</div>

	</form>
</div>
